<!doctype html>
<?
$fi=$_GET["fechaini"];
$ff=$_GET["fechafin"];
//require("../conectar.php");
//require("funciones.php");
?>


<table class="ocupacion">
 <tr>	
    <th colspan="4">CLIENTES QUE NO RENTARON</th>
      </tr>
  <tr>
    <th>Medio </th>
    <th>Submedio </th>
    <th>No. de Clientes</th>
    <th>porcentaje</th>
  </tr>
  <?
 $totalclientes=0;$x=0;
  $sql="SELECT  (Select descripcion from subdirectorios where id_subdir=r.submedio) as descripcion , (Select canal from medio where id=r.submedio) as canal, count(r.id_renta) as con from renta as r 
  INNER JOIN conceptos as c ON c.id_renta=r.id_renta 
  where(c.dia_inicio between '$fi' and '$ff') and c.status_renta IN('','LIBRE')  group by descripcion ";  
	$query=mysql_query($sql);
	while($medio=mysql_fetch_array($query))
		{
		$totalclientes=$medio["con"]+$totalclientes;
		}
	$query=mysql_query($sql);
		while($medio=mysql_fetch_array($query))
		{
		$x++;
		if($medio["canal"]==""){$m="NO CAPTURADO";}
		else{$m=$medio["canal"];}
		if($medio["descripcion"]==""){$d="NO CAPTURADO";}
		else{$d=$medio["descripcion"];}
 ?><tr>
    <td>
    <input name="medio<?echo$x?>" type="hidden" id="medio<?echo$x?>" value="<?echo$m;?>" ><?echo$m?></td>
	 <td>
    <input name="submedio<?echo$x?>" type="hidden" id="submedio<?echo$x?>" value="<?echo$d;?>" ><?echo$d?></td>
    <td>
    <input name="cliente<?echo$x?>" type="text" id="cliente<?echo$x?>" value="<?echo$medio["con"];?>" readonly></td>
    <td>
	<input name="porcliente<?echo$x?>" type="text" id="porcliente<?echo$x?>" value="<?echo porcentaje($por=($medio["con"]/$totalclientes)*100);?>" readonly></td>
  </tr>
  <?}?>
  <tr>
    <td></td>
    <td>Total</td>
    <td><?echo ($totalclientes);?></td>
    <td><?echo porcentaje(100);?></td>
  </tr>
</table>
<br>
<table class="ocupacion">
  <tr>	
    <th colspan="4">CLIENTES QUE RENTARON</th>
      </tr>
  <tr>
    <th>Medio </th>
    <th>Submedio </th>
    <th>No. de Clientes</th>
    <th>porcentaje</th>
  </tr>
  <?
 $totalclientes=0;$x=0;
   echo$sql="SELECT  id_renta FROM conceptos as c 
     INNER JOIN pagos as p ON p.id_concepto=c.id_cocnepto 
   where(p.fecha between '$fi' and '$ff') and p.concepto IN('RENTA','SEGUIMIENTO') group by p.id_concepto ";  
   	
	//$query=mysql_query($sql);
while($rentas=mysql_fetch_array){$ren.="'".$renta["id_renta"]."',";}
 $ren.="'0'";  
   $sql="SELECT  (Select descripcion from subdirectorios where id_subdir=r.submedio) as descripcion , (Select canal from medio where id=r.submedio) as canal, count(r.id_renta) as con from renta as r 
   wherer.id_renta IN($ren) group by descripcion ";  
	$query=mysql_query($sql);
	while($medio=mysql_fetch_array($query))
		{
		$totalclientes=$medio["con"]+$totalclientes;
		}
	//$query=mysql_query($sql);
		while($medio=mysql_fetch_array($query))
		{
		$x++;
		if($medio["canal"]==""){$m="NO CAPTURADO";}
		else{$m=$medio["canal"];}
		if($medio["descripcion"]==""){$d="NO CAPTURADO";}
		else{$d=$medio["descripcion"];}
 ?><tr>
    <td>
    <input name="medio<?echo$x?>" type="hidden" id="medio<?echo$x?>" value="<?echo$m;?>" ><?echo$m?></td>
	 <td>
    <input name="submedio<?echo$x?>" type="hidden" id="submedio<?echo$x?>" value="<?echo$d;?>" ><?echo$d?></td>
    <td>
    <input name="cliente<?echo$x?>" type="text" id="cliente<?echo$x?>" value="<?echo$medio["con"];?>" readonly></td>
    <td>
	<input name="porcliente<?echo$x?>" type="text" id="porcliente<?echo$x?>" value="<?echo porcentaje($por=($medio["con"]/$totalclientes)*100);?>" readonly></td>
  </tr>
  <?}?>
  <tr>
    <td></td>
    <td>Total</td>
    <td><?echo ($totalclientes);?></td>
    <td><?echo porcentaje(100);?></td>
  </tr>
</table>


